package com.ruoyi.appService.mentalTestList.controller;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.appService.mentalTestList.domain.ZMentaltest;
import com.ruoyi.appService.mentalTestList.service.IZMentaltestService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 心理测试Controller
 * 
 * @author anjiao
 * @date 2025-05-10
 */
@RestController
@RequestMapping("/mentalTest/mentalTest")
public class ZMentaltestController extends BaseController
{
    @Autowired
    private IZMentaltestService zMentaltestService;

    /**
     * 查询心理测试列表
     */
    @PreAuthorize("@ss.hasPermi('mentalTest:mentalTest:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZMentaltest zMentaltest)
    {
        startPage();
        List<ZMentaltest> list = zMentaltestService.selectZMentaltestList(zMentaltest);
        return getDataTable(list);
    }


//    查询所有测试题
@GetMapping("/listAll")
    public TableDataInfo listAll(ZMentaltest zMentaltest)
    {
        List<ZMentaltest> list = zMentaltestService.selectZMentaltestList(zMentaltest);
        return getDataTable(list);
    }



    /**
     * 导出心理测试列表
     */
    @PreAuthorize("@ss.hasPermi('mentalTest:mentalTest:export')")
    @Log(title = "心理测试", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZMentaltest zMentaltest)
    {
        List<ZMentaltest> list = zMentaltestService.selectZMentaltestList(zMentaltest);
        ExcelUtil<ZMentaltest> util = new ExcelUtil<ZMentaltest>(ZMentaltest.class);
        util.exportExcel(response, list, "心理测试数据");
    }

    /**
     * 获取心理测试详细信息
     */
    @PreAuthorize("@ss.hasPermi('mentalTest:mentalTest:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(zMentaltestService.selectZMentaltestById(id));
    }

    /**
     * 新增心理测试
     */
    @PreAuthorize("@ss.hasPermi('mentalTest:mentalTest:add')")
    @Log(title = "心理测试", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZMentaltest zMentaltest)
    {
        return toAjax(zMentaltestService.insertZMentaltest(zMentaltest));
    }

    /**
     * 修改心理测试
     */
    @PreAuthorize("@ss.hasPermi('mentalTest:mentalTest:edit')")
    @Log(title = "心理测试", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZMentaltest zMentaltest)
    {
        return toAjax(zMentaltestService.updateZMentaltest(zMentaltest));
    }

    /**
     * 删除心理测试
     */
    @PreAuthorize("@ss.hasPermi('mentalTest:mentalTest:remove')")
    @Log(title = "心理测试", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zMentaltestService.deleteZMentaltestByIds(ids));
    }



//    根据用户id查询所有已经完成的测试
    @GetMapping("/completedTest")
    public AjaxResult  selectAllCompentedTest   (HttpServletRequest request)
    {
        return success(zMentaltestService.selectCompletedTestList(request) );
    }

//新增已完成的测试
@GetMapping("/insertCompletedTest/{id}")
public AjaxResult  insertCompentedTest   (@PathVariable int id,HttpServletRequest request)
{

    zMentaltestService.insertCompletedTestList(id,request);
    return success( );
}






}
